package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.AdminUpdateStaticDataRequest;
import com.sc.nft.admin.request.UpStaticDataRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.StaticData;
import com.sc.nft.entity.vo.AdminStaticDataVO;
import com.sc.nft.service.StaticDataService;
import com.sc.nft.service.UserAssetsService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

/**
 * 菜单表服务控制器
 *
 * @author rdg
 * @since 2022-06-06
 * @description
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/settingStatic")
@Api(tags = "静态数据设置模块")
public class SettingsStaticDataController {
    private final StaticDataService staticDataService;

    @PostMapping(value = "/getQiniuToken", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取七牛图片token", notes = "获取七牛图片token", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result getQiniuToken() {
        return Result.success(staticDataService.getQiniuToken());
    }

    @PostMapping(value = "/getAdminStaticData", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取静态设置数据", notes = "获取静态设置数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminStaticDataVO>> getStaticData() {
        List<StaticData> adminStaticData = staticDataService.getAdminStaticData();
        return Result.successColl(adminStaticData, AdminStaticDataVO.class);
    }

    @PostMapping(value = "/updateStaticData", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改静态数据", notes = "修改静态数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateStaticData(@Valid @RequestBody AdminUpdateStaticDataRequest adminUpdateStaticDataRequest) {
        List<UpStaticDataRequest> list = adminUpdateStaticDataRequest.getList();
        for (UpStaticDataRequest upStaticDataRequest : list) {
            staticDataService.updateStaticData(upStaticDataRequest.getType(), upStaticDataRequest.getValue());
        }
        return Result.success();
    }
}
